package com.zy.test.threaddemo;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author MissZhou
 */
public class CreateByCallable implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        int sum = 0;
        for (int i = 0; i < 10; i++) {
            sum += i;

        }
        return sum;
    }

    public static void main(String[] args) {
        FutureTask<Integer> futureTask = new FutureTask<>(new CreateByCallable());
        new Thread(futureTask).start();

        try {
            Integer sum = futureTask.get();
            System.out.println("获取子线程求和结果："+ sum);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }


}
